<script src="<%- Virtual_Path.Static %>jquery.plugin/birthday/birthday.js"></script>
<!-- 修改资料-->
<div class="x-header-top">
    <div class="header-inner">
        <h2 class="tit">基本资料</h2>
    </div>
</div>
<!-- 修改资料-->
<div class="main-container">
    <div class="profile-information">
        <div class="group-item">
            <div class="g-lab">
                ID：
            </div>
            <div class="g-field">
                <em class="color-orange" id="J_Base_User_ID"></em>
            </div>
        </div>
        <div class="group-item">
            <div class="g-lab">
                昵称：
            </div>
            <div class="g-field">
                <input type="text" name="NickName" id="" value="" placeholder="昵称" maxlength="8" class="g-w241"/><b
                        class="g-info-tips">昵称长度 2-8个字之间</b>
            </div>

        </div>
        <div class="group-item">
            <div class="g-lab">
                性别：
            </div>
            <div class="g-field">
                <ul class="g-inline" id="user-sex">
                    <li>
                        <div class="radio-btn" id="J_Base_SexChange_1"><i><input type="radio" name="User_Sex" value="1"></i></div>
                        男
                    </li>
                    <li>
                        <div class="radio-btn" id="J_Base_SexChange_2"><i><input type="radio" name="User_Sex" value="2"></i></div>
                        女
                    </li>
                </ul>
            </div>
        </div>

        <div class="group-item">
            <div class="g-lab">
                生日：
            </div>
            <div class="g-field">
                <select name="Birthday_Year" id="sel_year" rel=""></select>
                年
                <select name="Birthday_Month" id="sel_month" rel=""></select>
                月
                <select name="Birthday_Day" id="sel_day" rel=""></select>
                日
            </div>
        </div>

        <div class="group-item">
            <div class="g-field g-field-button">
                <input type="button" class="g-save-button" id="J_Base_Button" value="保 存"/>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        if (!_StateData.IsLogin) {
            $.CommonMain.Modal_Tip('请先登录', {Timeout: 1000});
            location.href = '/';
        }
        $('#J_Base_User_ID').text(_StateData.User_ID);
        $('input[name="NickName"]').val(_StateData.NickName);
        if (_PageData.UserInfo.Sex == 1) {
            $('#J_Base_SexChange_1').addClass('checkedRadio');
            $('#J_Base_SexChange_1').find('input').attr("checked", "checked");
        } else {
            $('#J_Base_SexChange_2').addClass('checkedRadio');
            $('#J_Base_SexChange_2').find('input').attr("checked", "checked");
        }
        $('.radio-btn').on("click", function () {
            $("#user-sex .radio-btn").removeClass("checkedRadio").find("input").removeAttr("checked");
            $(this).addClass('checkedRadio').find('input').attr("checked", "checked");
        });
        //年月日
        var strs = new Array(); //定义一数组
        if (_PageData.UserInfo.Birthday) {
            strs = _PageData.UserInfo.Birthday.split("-"); //字符分割
            $('#sel_year').attr('rel', strs['0']);
            $('#sel_month').attr('rel', strs['1']);
            $('#sel_day').attr('rel', strs['2']);
        }
        $.ms_DatePicker({
            YearSelector: ".sel_year",
            MonthSelector: ".sel_month",
            DaySelector: ".sel_day"
        });
        $.ms_DatePicker();
        $('#J_Base_Button').on('click', function () {
            var params = {};
            params.NickName = $.trim($('input[name="NickName"]').val()).replace(/[ ]/g, "");
            params.Sex = $.trim($("input[name='User_Sex'][checked]").val());
            params.Birthday_Year = $.trim($('#sel_year').val());
            params.Birthday_Month = $.trim($('#sel_month').val());
            params.Birthday_Day = $.trim($('#sel_day').val());
            if (params.NickName.length > 8) {
                $.CommonMain.Modal_Tip('昵称不能超过8个字符', {Timeout: 1000});
                $('input[name="NickNames"]').focus();
                return false;
            }
            if (params.NickName.length < 2) {
                $.CommonMain.Modal_Tip('昵称不能少于2个字符', {Timeout: 1000});
                $('input[name="NickNames"]').focus();
                return false;
            }
            if (!params.NickName) {
                $.CommonMain.Modal_Tip('昵称不能为空', {Timeout: 1000});
                $('input[name="NickName"]').focus();
                return false;
            }
            if (!params.Birthday_Year) {
                $.CommonMain.Modal_Tip('请选择年份', {Timeout: 1000});
                return false;
            }
            if (!params.Birthday_Month) {
                $.CommonMain.Modal_Tip('请选择月份', {Timeout: 1000});
                return false;
            }
            if (!params.Birthday_Day) {
                $.CommonMain.Modal_Tip('请选择天', {Timeout: 1000});
                return false;
            }
            $.KOC.Loading.Open();
            $.ajax({
                url: '/ajax/user.user-info.update',
                type: 'post',
                dataType: 'json',
                data: {
                    NickName: params.NickName,
                    Sex: params.Sex,
                    Birthday: params.Birthday_Year + '-' + params.Birthday_Month + '-' + params.Birthday_Day
                },
                success: function (data) {
                    $.KOC.Loading.Close();
                    if (data.flag !== 0) {
                        $.CommonMain.Modal_Tip(data.msg + "(" + data.flag + ")", {Timeout: 2000});
                        return;
                    }
                    $.CommonMain.Modal_Tip('基本资料修改完成', {
                        Timeout: 1000,
                        onClose: function () {
                            location.href = "/member";
                        }
                    });
                }
            });

        });

    })
</script>
